﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using WebApplication2;

namespace WebApplication2
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterOpenAuth();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            if (!Roles.RoleExists("Test"))
            {
                Roles.CreateRole("Test");
            }

            if (!Roles.RoleExists("Admin"))
            {
                Roles.CreateRole("Admin");
            }

            if (!Roles.RoleExists("Lees"))
            {
                Roles.CreateRole("Lees");
            }

            if (!Roles.RoleExists("Schrijf"))
            {
                Roles.CreateRole("Schrijf");
            }

            if (Membership.FindUsersByName("Eusebius").Count == 0)
            {
                Membership.CreateUser("Eusebius", "test123");
            }

            if (Membership.FindUsersByName("Sander").Count == 0)
            {
                Membership.CreateUser("Sander", "test123");
            }

            if (Membership.FindUsersByName("Pieter").Count == 0)
            {
                Membership.CreateUser("Pieter", "test123");
            }

            if (Membership.FindUsersByName("Dennis").Count == 0)
            {
                Membership.CreateUser("Dennis", "test123");
            }

            if (Membership.FindUsersByName("Eusebius").Count == 0)
            {
                Membership.CreateUser("Eusebius", "test123");
            }

            if (!Roles.IsUserInRole("Eusebius", "Admin"))
            {
                Roles.AddUserToRole("Eusebius", "Admin");
            }
            if (!Roles.IsUserInRole("Sander", "Admin"))
            {
                Roles.AddUserToRole("Sander", "Admin");
            }
            if (!Roles.IsUserInRole("Pieter", "Schrijf"))
            {
                Roles.AddUserToRole("Pieter", "Schrijf");
            }
            if (!Roles.IsUserInRole("Dennis", "Lees"))
            {
                Roles.AddUserToRole("Dennis", "Lees");
            }
        }

        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown

        }

        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

        }
    }
}
